#include <iostream>
#include <sys/time.h>
#include <fstream>
#include <chrono>
#include <ctime>
#include <vector>
using namespace std;


bool negri(string pon){
    vector<string> negr9 = {};
    // cout << pon.length()-1;
    for (int i = 0; i < pon.length();i++){
        string x;
        x = pon[i];        
        
        if (x == "(" || x == "[" || x == "{"){
            // cout << i<< "\n";
            //cout << "###"<<  x <<endl;
            negr9.push_back(x);
            
        }
        else{
            if (negr9.size() == 0){
                return false;
            }
            if (x == "}" && negr9[negr9.size()-1] == "{"){
                //cout << "###{"<<  x <<endl;
                negr9.pop_back();
            }
            else if((x == ")") && (negr9[negr9.size()-1] == "(") ){
                //cout << "###("<<  x <<endl;
                negr9.pop_back();
            }
            else if((x == "]") && (negr9[negr9.size()-1] == "[")){
                //cout << "###["<<  x <<endl;
                negr9.pop_back();
            }
            else if((x == ">") && (negr9[negr9.size()-1] == "<")){
                //cout << "###["<<  x <<endl;
                negr9.pop_back();
            }
            else{
                return false;
            }
        }
    }
    if(negr9.size() == 0){
        return true;
    }
    return false;
}   

int main()
{
    string pon;
    cout << "введите скобочную последовательность:";
    cin >> pon;
    
    // negri(pon);
    if (negri(pon) ){
        cout << "True";
    }
    else{
        cout << "False";
    }
    cout << endl;
    // cout << ? "true" : "false";
}

